//
//  SQNewTableViewCell.m
//  energy
//
//  Created by 苏青 on 2021/10/11.
//

#import "SQNewTableViewCell.h"
#import "SQNewModel.h"

#import "NSString+NCDate.h"
#import "NSString+WPAttributedMarkup.h"

@implementation SQNewTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}


+(CGFloat)cellHeight:(BaseModel *)model{
    return W(80);
}

-(void)setModel:(BaseModel<BaseCellModelProtocol> *)model{
    SQNewModelData * dataModel = model;
    self.lab_time.text =[NSString formateDateToDay:[dataModel.a_addtime substringWithRange:NSMakeRange(6,13)]];
    self.lab_people.text = [NSString stringWithFormat:@"发布人:%@",dataModel.a_username];
    if ([[self timerCompare:[NSString formateDateToDay:[dataModel.a_addtime substringWithRange:NSMakeRange(6,13)]] finishTimer:dataModel.a_standard_new] isEqualToString:@"0"]) {
        NSDictionary * styles = @{@"color":[UIColor colorNamed:@"ff00Color"]};
         NSString * str = [NSString stringWithFormat:@"<color>NEW</color>%@",dataModel.a_title];
       
        self.lab_name.attributedText = [str attributedStringWithStyleBook:styles];
    
    }else{
        self.lab_name.text = dataModel.a_title;
    }
}


-(NSString *)timerCompare:(NSString *)starTimer finishTimer:(NSString *)finishTimer{
    
    NSString * state;
    
    BOOL result = [starTimer compare:finishTimer] == NSOrderedSame;
//    NSLog(@"result:%d",result);
    if (result==1) {
//       开始时间和结束时间相等;
        state = @"1";
    
    }
    
    BOOL result1 = [starTimer compare:finishTimer]==NSOrderedDescending;
//    NSLog(@"result1:%d",result1);
    if (result1==1) {
//        开始时间晚于结束时间
        state = @"2";
        
    }

    
    BOOL result2 = [starTimer compare:finishTimer]==NSOrderedAscending;
//    NSLog(@"result2:%d",result1);
    if (result2==1) {
//      开始时间早于结束时间;
        state = @"0";
        
    }
    return state;
    
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
